cmake_minimum_required(VERSION 2.8.9)

project(nxt-serial)

set(LIB_MAJOR 0)
set(LIB_MINOR 9)
set(LIB_BUILD 0)
set(LIB_REVISION 0)
set(LIB_VERSION ${LIB_MAJOR}.${LIB_MINOR}.${LIB_REVISION})

option(CONNECTION_CONTROL "Enables automatic reset if connections interruption is detected" OFF)

# do not set to CMAKE_CURRENT_SOURCE_DIR since it may be called from driver build
set(src_dir "${CMAKE_CURRENT_LIST_DIR}")
if (NOT NETXTRANSPORT_HEADER)
	set(inc_dir ${src_dir} /usr/local/include/netxtransport/)
else(NOT NETXTRANSPORT_HEADER)
	set(inc_dir ${src_dir} ${NETXTRANSPORT_HEADER})
endif(NOT NETXTRANSPORT_HEADER)

if(NOT EXECUTABLE_OUTPUT_PATH)
        set(LIBRARY_OUTPUT_PATH ./connectors)
else(NOT EXECUTABLE_OUTPUT_PATH)
        set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/connectors)
endif(NOT EXECUTABLE_OUTPUT_PATH)

if(NOT CONNECTOR_INSTALL_PATH)
        set(CONNECTOR_INSTALL_PATH "bin/connectors")
endif(NOT CONNECTOR_INSTALL_PATH)

# file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "${src_dir}/*.c")
include_directories(${inc_dir})

add_definitions(-D_GNU_SOURCE)

# link and create shared & static library
add_library(${PROJECT_NAME} SHARED ${SOURCES})

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")

if (CONNECTION_CONTROL)
	add_definitions(-DCONNECTION_CONTROL)
	target_link_libraries(${PROJECT_NAME} "-ludev")
endif(CONNECTION_CONTROL)
